import { defHttp } from '/@/utils/http/axios';
import { PageResult } from '@/api/model/pageResult';
import { ContentTypeEnum } from '@/enums/httpEnum';
import { QueryCouponVo } from '@/api/base-data/coupon/model/queryCouponVo';
import { QueryCouponBo } from '@/api/base-data/coupon/model/queryCouponBo';
import { GetCouponBo } from '@/api/base-data/coupon/model/getCouponBo';
import { CreateCouponVo } from '@/api/base-data/coupon/model/createCouponVo';
import { UpdateCouponVo } from '@/api/base-data/coupon/model/updateCouponVo';
import { QueryCouponProductSelectorVo } from '@/api/base-data/coupon/model/queryCouponProductSelectorVo';
import { CouponProductSelectorBo } from '@/api/base-data/coupon/model/couponProductSelectorBo';
import { CouponSelectorBo } from '@/api/base-data/coupon/model/couponSelectorBo';

const baseUrl = '/basedata/coupon';
const selectorBaseUrl = '/selector';
const region = 'cloud-api';

/**
 * 查询商品列表
 * @param params
 * @returns {Promise<CouponProductSelectorBo[]>}
 */
export function selectorProduct(
  params: QueryCouponProductSelectorVo,
): Promise<CouponProductSelectorBo[]> {
  return defHttp.get<CouponProductSelectorBo[]>(
    {
      url: selectorBaseUrl + '/coupon-product',
      params,
    },
    {
      region,
    },
  );
}

export function selector(params: QueryCouponVo): Promise<PageResult<QueryCouponBo>> {
  return defHttp.get<PageResult<QueryCouponBo>>(
    {
      url: selectorBaseUrl + '/coupon',
      params,
    },
    {
      region,
    },
  );
}

export function loadCoupon(ids: string[]): Promise<CouponSelectorBo[]> {
  return defHttp.post<CouponSelectorBo[]>(
    {
      url: selectorBaseUrl + '/coupon/load',
      data: ids,
    },
    {
      contentType: ContentTypeEnum.JSON,
      region,
    },
  );
}

/**
 * 查询列表
 * @param params
 * @returns {Promise}
 */
export function query(params: QueryCouponVo): Promise<PageResult<QueryCouponBo>> {
  return defHttp.get<PageResult<QueryCouponBo>>(
    {
      url: baseUrl + '/query',
      params: params,
    },
    {
      region,
    },
  );
}

/**
 * 根据ID查询
 * @param id
 * @returns {Promise}
 */
export function get(id: String): Promise<GetCouponBo> {
  return defHttp.get<GetCouponBo>(
    {
      url: baseUrl,
      params: {
        id,
      },
    },
    {
      region,
    },
  );
}

/**
 * 新增
 * @param params
 * @returns {Promise}
 */
export function create(params: CreateCouponVo): Promise<void> {
  return defHttp.post<void>(
    {
      url: baseUrl,
      data: params,
    },
    {
      contentType: ContentTypeEnum.FORM_URLENCODED,
      region,
    },
  );
}

/**
 * 修改
 * @param params
 * @returns {Promise}
 */
export function update(params: UpdateCouponVo): Promise<void> {
  return defHttp.put<void>(
    {
      url: baseUrl,
      data: params,
    },
    {
      contentType: ContentTypeEnum.FORM_URLENCODED,
      region,
    },
  );
}
